package com.chanyachting.emall.action.companyproduct;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.chanyachting.emall.domain.Companyproduct;
import com.chanyachting.emall.util.DateUtil;
import com.chanyachting.emall.util.RequestUtil;

public class CompanyproductAction extends DispatchAction {

	
	//获得待审核产品列表
	public ActionForward checklist(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		ru.setAttribute("productList", Companyproduct.listByStatus("01"));
		
		return mapping.findForward("list");
	}
	
	
	//显示产品信息
	public ActionForward show(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		int id=Integer.parseInt(ru.getParameter("id", "0"));
		
		Companyproduct product=new Companyproduct(id);
		
		ru.setAttribute("product", product);
		
		return mapping.findForward("show");
	}
	
	
	//发布产品
	public ActionForward publish(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		RequestUtil ru=new RequestUtil(request);
		
		int id=Integer.parseInt(ru.getParameter("id", "0"));
		
		Companyproduct product=new Companyproduct(id);
		
		if(product!=null){
			
			product.setStatus("02");
			
			product.setUpdateDate(DateUtil.getDate());
			
			if(product.update()){
				
				ru.setSuccessMsg();
				
			}else{
				
				ru.setFailMsg();
			}
		}
		
		
		ru.setAttribute("product", product);
		
		return mapping.findForward("show");
	}
	
	
	//退回产品
	public ActionForward goback(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		
		RequestUtil ru=new RequestUtil(request);
		
		int id=Integer.parseInt(ru.getParameter("id", "0"));
		
		Companyproduct product=new Companyproduct(id);
		
		if(product!=null){
			
			product.setStatus("00");
			
			product.setUpdateDate(DateUtil.getDate());
			
			if(product.update()){
				
				ru.setSuccessMsg();
				
			}else{
				
				ru.setFailMsg();
			}
		}
		
		ru.setAttribute("product", product);
		
		
		return mapping.findForward("show");
	}
	
	

}
